package com.ruoyi.web.controller.training;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.system.domain.EmpowermentTraining;
import com.ruoyi.system.service.IEmpowermentTrainingService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 赋能培训Controller
 * 
 * @author ruoyi
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/trainings/training")
public class EmpowermentTrainingController extends BaseController
{
    @Autowired
    private IEmpowermentTrainingService empowermentTrainingService;

    /**
     * 查询赋能培训列表
     */
    @Anonymous

    @GetMapping("/list")
    public TableDataInfo list(EmpowermentTraining empowermentTraining)
    {
        startPage();
        List<EmpowermentTraining> list = empowermentTrainingService.selectEmpowermentTrainingList(empowermentTraining);
        return getDataTable(list);
    }

    /**
     * 导出赋能培训列表
     */

    @Log(title = "赋能培训", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmpowermentTraining empowermentTraining)
    {
        List<EmpowermentTraining> list = empowermentTrainingService.selectEmpowermentTrainingList(empowermentTraining);
        ExcelUtil<EmpowermentTraining> util = new ExcelUtil<EmpowermentTraining>(EmpowermentTraining.class);
        util.exportExcel(response, list, "赋能培训数据");
    }

    /**
     * 获取赋能培训详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:post:query')")
    @GetMapping(value = "/{trainingId}")
    public AjaxResult getInfo(@PathVariable("trainingId") String trainingId)
    {
        return success(empowermentTrainingService.selectEmpowermentTrainingByTrainingId(trainingId));
    }

    /**
     * 新增赋能培训
     */
    @PreAuthorize("@ss.hasPermi('system:post:add')")
    @Log(title = "赋能培训", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmpowermentTraining empowermentTraining)
    {
        return toAjax(empowermentTrainingService.insertEmpowermentTraining(empowermentTraining));
    }

    /**
     * 修改赋能培训
     */
    @PreAuthorize("@ss.hasPermi('system:post:edit')")
    @Log(title = "赋能培训", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmpowermentTraining empowermentTraining)
    {
        return toAjax(empowermentTrainingService.updateEmpowermentTraining(empowermentTraining));
    }

    /**
     * 删除赋能培训
     */
    @PreAuthorize("@ss.hasPermi('system:post:remove')")
    @Log(title = "赋能培训", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trainingIds}")
    public AjaxResult remove(@PathVariable String[] trainingIds)
    {
        return toAjax(empowermentTrainingService.deleteEmpowermentTrainingByTrainingIds(trainingIds));
    }
}
